package module16;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.internal.Coordinates;
import org.openqa.selenium.internal.Locatable;
import org.openqa.selenium.support.events.EventFiringWebDriver;
import org.openqa.selenium.support.events.internal.EventFiringMouse;

public class Makemytrip {

	/**
	 * @param args
	 */
	public static WebDriver web_driver ;
	public static void main(String[] args) {
		web_driver = new FirefoxDriver();
		EventFiringWebDriver driver = new EventFiringWebDriver(web_driver);
		MyListener listener = new MyListener();
		driver.register(listener);
       driver.navigate().to("http://www.makemytrip.com");
		
		EventFiringMouse mousemvmt = new EventFiringMouse(driver, listener);
		Locatable locate = (Locatable) driver.findElement(By.xpath("//*[@id='dialog-modal']/span/img"));
		Coordinates cordinate = locate.getCoordinates();
		
		try
		{
			mousemvmt.mouseDown(cordinate);
			mousemvmt.click(cordinate);
		}
				
		catch(Throwable t)
		{
			System.out.println("Error");
		}
		List<WebElement> radiolists = driver.findElements(By.xpath("//input[@name='radtripType']"));
		
		for(int i=0;i<radiolists.size();i++)
		{
				String value= radiolists.get(i).getAttribute("value");
				System.out.println(value);
				if(radiolists.get(i).getAttribute("value").equals("R"))
				{
					radiolists.get(i).click();
				}
		}
		
		//if selenium cannot identify some object we can use javascript and make it identify it.
		//((JavascriptExecutor) driver).executeScript("document.getElementById('radtripType').click();");
		
		

	}

}
